package org.yuanqiframework.yuanqi.boot.sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.yuanqiframework.yuanqi.boot.sys.entity.SysRoleMenu;
import org.yuanqiframework.yuanqi.boot.sys.mapper.SysRoleMenuMapper;
import org.yuanqiframework.yuanqi.boot.sys.service.SysRoleMenuService;
import org.apache.ibatis.executor.BatchResult;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.LinkedList;
import java.util.List;

/**
 * @author cbt28
 * @description 针对表【sys_role_menu】的数据库操作Service实现
 * @createDate 2025-08-23 23:41:09
 */
@Service
public class SysRoleMenuServiceImpl extends ServiceImpl<SysRoleMenuMapper, SysRoleMenu>
        implements SysRoleMenuService {
    @Resource
    private SysRoleMenuMapper sysRoleMenuMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int updateRoleMenus(String roleId, List<Long> ids) {
        sysRoleMenuMapper.delete(new LambdaQueryWrapper<SysRoleMenu>().eq(SysRoleMenu::getRoleId, roleId));
        List<SysRoleMenu> list = new LinkedList<>();
        for (Long id : ids) {
            SysRoleMenu sysRoleMenu = new SysRoleMenu();
            sysRoleMenu.setRoleId(roleId);
            sysRoleMenu.setMenuId(id);
            list.add(sysRoleMenu);
        }
        List<BatchResult> insert = sysRoleMenuMapper.insert(list);
        return insert.size();
    }
}




